package polyn;

import static java.lang.Math.*;

public class PolynFamily {

    public static final int degree = 6;
    private final static int r0 = 1, r1 = 2;
    private static int N;
    private final static double _4_sq2 = 4 / sqrt(2);
    private final static double sq3 = sqrt(3);
    private final static Pair R0 = new Pair(2, 2),
            R1 = new Pair(-1 + sq3, 1 + sq3),
            R2 = new Pair(1 + sq3, -1 + sq3),
            R3 = new Pair(-2, -2),
            R4 = new Pair(1 - sq3, -1 - sq3),
            R5 = new Pair(-1 - sq3, 1 - sq3);
    public final static Pair[] rootsRotPi4 = {R0, R1, R2, R3, R4, R5};
    private LagrangePolyn[] TPolynFamily;
    private Pair[] points;

    public PolynFamily(int n) {
        PolynFamily.N = n;
        TPolynFamily = new LagrangePolyn[ n ];
        for (int k = 0 ; k < n ; k++) {
            points = calculatePoints(k);
            TPolynFamily[k] = new LagrangePolyn(points);
//            System.out.println(TPolynFamily[k].L(points[0].x));
        }

    }

    private Pair[] calculatePoints(int k) {
        int[] kbin = kToBinary(k);

        Pair[] ret = new Pair[ degree ];
        for (int i = 0 ; i < degree ; i++) {
            ret[i] = kbin[i] == 0 ? rootsRotPi4[i].times(_4_sq2 * r0) : rootsRotPi4[i].times(_4_sq2 * r1);

        }
//        System.out.println(Arrays.toString(ret));
        return ret;
    }

    private int[] kToBinary(int k) {
        int[] ret = new int[ degree ];
        String kS = Integer.toBinaryString(k);
        for (int i = 0 ; i < degree ; i++) {
            if (i < kS.length()) {
                if (kS.charAt(i) == '0') {
                    ret[i] = 0;
                } else {
                    ret[i] = 1;
                }
            } else {
                ret[i] = 0;
            }
        }
//        System.out.println(Arrays.toString(ret));
        return ret;
    }
}













